package unittest.docsync;

import java.util.Date;
import java.util.Formatter;
import java.util.List;
import java.util.ListIterator;

import docsync.ExtensionMapper;
import docsync.FileInterface;
import docsync.FolderInterface;
import docsync.FolderSync;
import docsync.GoogleDocSync;
import docsync.GoogleFolder;
import docsync.TestStubFolder;
import docsync.FolderSync.Action;
import docsync.doclist.DocListRequest;

public class UnitTestFolderSyncG {

	/**
	 * @param args
	 * @throws Exception
	 */
	public static void main(String[] args) throws Exception {
		String localpath = "C:\\Documents and Settings\\michael\\My Documents"
				+ "\\school\\fall 2010\\cmpe207\\project\\testA";

		// this is the facade to the core functionality
		// takes a local folder, username, password
		GoogleDocSync sync = new GoogleDocSync(new TestStubFolder(localpath),
				"207project@gmail.com", "207group04");

		System.out.println("==List Remote Files");
		for (FileInterface file : sync.getRemoteFiles()) {//list all remote files
			StringBuilder sb = new StringBuilder();
			Formatter f = new Formatter(sb);
			f.format("%s | %s", file.getFilename(), new Date(file.lastModify()));
			System.out.println(sb);
		}
		System.out.println("==List Local Files");
		for (FileInterface file : sync.getLocalFiles()) {//list all remote files
			StringBuilder sb = new StringBuilder();
			Formatter f = new Formatter(sb);
			f.format("%s | %s", file.getFilename(), new Date(file.lastModify()));
			System.out.println(sb);
		}
		System.out.println("==List Pending Actions");

		List<FolderSync.Action> todos = sync.synchronize();
		ListIterator<Action> iter = todos.listIterator();
		while (iter.hasNext()) {
			Action action = iter.next();
			System.out.println(action.toString());// print a description
			action.perform();// complete the pending action
		}
	}

}
